<template>
  <div style="text-align: left">
    <div style="width: 100%;margin-bottom: 20px">
      <el-button type="danger" @click="acquires">一键获取</el-button>
    </div>
    <el-tree
      :data="treeData"
      :props="defaultProps"
      :default-expanded-keys="[1]"
      @node-click="handleNodeClick"
    ></el-tree>
  </div>
</template>

<script>
export default {
  name: "answer",
  data() {
    return {
      treeData: [],
      defaultProps: {
        children: "children",
        label: "name"
      }
    };
  },
  mounted() {
    this.loadFun();
  },
  methods: {
    handleNodeClick(data) {
      console.log(data);
    },
    loadFun() {
      let that = this;
      that
        .$post("vpo/md/answer", {})
        .then(response => {
          console.log(response);
          that.treeData = response.data;
        })
        .catch(err => {
          that.$message.error(err);
        });
    },
    // 一键获取
    acquires() {
      let that = this;
      const loading = that.$loading({
        lock: true,
        text: "拼命查询中",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      that
        .$post("vpo/md/syncAnswer", {})
        .then(response => {
          if (response.resultCode === 1) {
            this.$message({
              message: response.msg,
              type: "success"
            });
            that.loadFun();
          } else {
            that.$message.error(err);
          }
          loading.close();
        })
        .catch(err => {
          that.$message.error(err);
          loading.close();
        });
    }
  }
};
</script>

<style scoped>
</style>
